package com.realestate.services;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.realestate.constants.AppConstant;
import com.realestate.dao.ProductQueryDao;
import com.realestate.model.BrtbProduct;

@Service
public class ProductQueryServiceImpl implements ProductQueryService {

	private static final Logger logger = Logger.getLogger(ProductQueryServiceImpl.class);

	@Autowired
	private ProductQueryDao productQueryDao;

	@Override
	public List<BrtbProduct> getListproductByCategoryCode(String categoryCode, Long limit, Long productId, String typeProduct) {
		List<BrtbProduct> results = productQueryDao.getListproductByCategoryCode(categoryCode, limit, productId, typeProduct);
		for(BrtbProduct product : results){
			if(product.getPicture() != null && product.getPicture() != ""){
				product.setPicture(product.getPicture().split(AppConstant.SEPERATOR_FILE_PICTURE)[0]);
			}
		}
		return results;
	}

	@Override
	public List<BrtbProduct> getListproductByCategoryCode(String categoryCode, Map<String, String> filter, Long limit) {
		return productQueryDao.getListproductByCategoryCode(categoryCode, filter, limit);
	}

	/**
	 * getAllCommonAttributeValue
	 * in session
	 */
	@Override
	public BrtbProduct findProductById(Long id) {
		BrtbProduct product = productQueryDao.find(id);
		return product;
	}

	@Override
	public Page<BrtbProduct> getPagingProduct(Pageable pageable, String categoryCode) {
		return productQueryDao.getPagingProduct(pageable, categoryCode);
	}

	@Override
	public Page<BrtbProduct> getPagingProductSimpleSearch(Pageable pageable,
			Map<String, String> attributes) {
		return productQueryDao.getPagingProductSimpleSearch(pageable, attributes);
	}

	@Override
	public Page<BrtbProduct> getPagingProduct(Pageable pageable,
			String categoryCode, String districtCode, String buildingCode) {
		return productQueryDao.getPagingProduct(pageable, categoryCode, districtCode, buildingCode);
	}
}
